package cate.game.role.farm.adventure.msg;


import cate.common.annotation.OperationSetter;
import cate.common.table.d.GDAdventure;
import cate.common.table.d.GDFunc;
import cate.common.table.d.GDHoardTask;
import cate.common.table.d.GDOperation;
import cate.common.table.farm.adventure.row.AdventureCharpterRow;
import cate.common.util.GameResult;
import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBAdventure;
import cate.game.role.farm.PlayTimes;
import cate.game.role.farm.adventure.QuickFightPlayTimes;
import easy.java.practice.errorcode.EcResult;

@ClientMsg(title = "主线快速补给 の 请求")
@OperationSetter(value = GDOperation.ADVENTURE_QUICK_FIGHT)
public class QuickFightReq implements MsgInput {
    @Override
    public void execute(GameBody game, ClientContext cc) {
        //防止玩家一关没打点击了快速补给，此时次数减少但没有发送奖励
        AdventureCharpterRow row = cc.getRole().getFarm().adventure.getRow();
        if (row==null){
            cc.getRole().getGame().notice.message(cc.getRole(),904042, "此通关数尚无对应奖励");
            return;
        }

        QuickFightPlayTimes playTimes = cc.getRole().getFarm().adventure.playTimes;
        GameResult<Void> available = playTimes.available(cc.getRole(), GDFunc.QUICK_FIGHT);
        if (available.ok()){
            playTimes.added();
            cc.getRole().send(new AdventurePlayTimesResp(playTimes));
            cc.getRole().getFarm().adventure.calAndSendReward(
                    GDAdventure.REWARD_TIME, GDFunc.QUICK_FIGHT, false);
            cc.getRole().getHistory().action.adventureFast();
            cc.getRole().getRes().hoard.addition.addTask(GDHoardTask.FAST_FIGHTING);
        }else {
            cc.getRole().getGame().notice.message(cc.getRole(),available.contentId,available.message);
        }
    }

    @Override
    public MsgConfig conf() {
        return MsgIdBAdventure.QUICK_FIGHT_REQ;
    }
}
